﻿
Imports System.Net.Mail 'this system.net.mail allows us ti import access to the mail classes. The asp.net web application will call the mailing system methods.


Public Class Contact
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub


    ' Protected Sub SendEmail(ByVal Sender As String, ByVal emailBody As String)

    'Dim email As MailMessage = New MailMessage(tbEmail.Text, "Ketan_P@hotmail.co.uk", "Senders Message", tbMessage.Text)
    '  Dim smtpClient As SmtpClient = New SmtpClient
    '  smtpClient.Host = "smtp.live.com"

    '  smtpClient.EnableSsl = True

    '  Dim credentials As New System.Net.NetworkCredential("Ketan_P@hotmail.co.uk", "Ketan")
    '  smtpClient.Credentials = credentials
    ' smtpClient.Send(email)

    '    lblSystemMessage.Text = "The mails has been successfully sent"

    '  End Sub




    ' Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click

    'Here we just formatting the page code to match up with email address to the email textbox and the rest. 

    'Dim sb As New StringBuilder

    '     sb.Append("Email Address: ")
    '   sb.Append(tbEmail.Text)
    '  sb.AppendLine()
    '   sb.Append("Your Message: ")
    '   sb.Append(tbMessage.Text)

    'The try statement is used to handle any error that might happen and it will returns an error message with the help of a label. This error message will prevent the system from crashing.
    '    Try
    '      SendEmail("Ketan_P@hotmail.com", sb.ToString())

    '    Catch ex As Exception
    '     lblSystemMessage.Text = "Error, please check and try again."
    '
    '   End Try
    'End Sub

    '**************************************************** from ttp://forums.asp.net/t/971802.aspx
    ' Public Shared Sub SendMailMessage(ByVal from As String, ByVal recepient As String, ByVal bcc As String, ByVal cc As String, ByVal subject As String, ByVal body As String)


    ' Instantiate a new instance of MailMessage
    'Dim mMailMessage As New MailMessage()

    ' Set the sender address of the mail message
    '    mMailMessage.From = New MailAddress(from)
    ' Set the recepient address of the mail message
    '    mMailMessage.To.Add(New MailAddress(recepient))

    ' Check if the bcc value is nothing or an empty string
    '   If Not bcc Is Nothing And bcc <> String.Empty Then
    ' Set the Bcc address of the mail message
    '      mMailMessage.Bcc.Add(New MailAddress(bcc))
    '   End If

    ' Check if the cc value is nothing or an empty value
    '   If Not cc Is Nothing And cc <> String.Empty Then
    ' Set the CC address of the mail message
    '      mMailMessage.CC.Add(New MailAddress(cc))
    '   End If

    ' Set the subject of the mail message
    '   mMailMessage.Subject = subject
    ' Set the body of the mail message
    '  mMailMessage.Body = body

    ' Set the format of the mail message body as HTML
    '  mMailMessage.IsBodyHtml = True
    ' Set the priority of the mail message to normal
    ' mMailMessage.Priority = MailPriority.Normal

    ' Instantiate a new instance of SmtpClient
    ' Dim mSmtpClient As New SmtpClient()
    ' Send the mail message
    ' mSmtpClient.Send(mMailMessage)
    '  End Sub
End Class